package com.cdh.oa.config;

import com.cdh.oa.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer{

    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 拦截器注册
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptor = registry.addInterceptor(loginInterceptor);
        interceptor.excludePathPatterns("/error","/404","/","/login","/kaptchaImage");
        //spring2.x 自定义的拦截器会拦截所有的资源，包括静态资源
        interceptor.excludePathPatterns("/commons/**","/css/*","/js/*","/images/*");
        interceptor.addPathPatterns("/**");
    }
}
